package com.coocaa.ops.admin.v1.tab.biz.impl;

import com.coocaa.ops.admin.base.AbstractBizImpl;
import com.coocaa.ops.admin.v1.dmp.biz.impl.DmpRegistryRlsInfoBizImpl;
import com.coocaa.ops.admin.v1.module.mapper.IModuleInfoHistoryMapper;
import com.coocaa.ops.admin.v1.tab.biz.ITabInfoBiz;
import com.coocaa.ops.admin.v1.tab.mapper.ITabInfoHistoryMapper;
import com.coocaa.ops.admin.v1.tab.mapper.ITabInfoMapper;
import com.coocaa.ops.common.core.base.enums.ResourceTypeEnum;
import com.coocaa.ops.common.core.base.mapper.IBaseHistoryMapper;
import com.coocaa.ops.common.core.base.mybatis.QueryTemplate;
import com.coocaa.ops.common.core.biz.module.entity.ModuleInfoHistoryEntity;
import com.coocaa.ops.common.core.biz.tab.entity.TabInfoEntity;
import com.coocaa.ops.common.core.biz.tab.entity.TabInfoHistoryEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author bjh
 * @description 版面信息原始表-biz层接口实现
 * @date 2020-06-15 16:27:18
 */
@Service
public class  TabInfoBizImpl extends AbstractBizImpl<ITabInfoMapper, TabInfoEntity> implements  ITabInfoBiz {
    @Autowired
    private ITabInfoHistoryMapper thisHistoryMapper;
    @Autowired
    private IModuleInfoHistoryMapper moduleInfoHistoryMapper;
    @Autowired
    private DmpRegistryRlsInfoBizImpl dmpRegistryRlsInfoBiz;

    @Override
    public IBaseHistoryMapper getHistoryMapper() {
        return thisHistoryMapper;
    }

    @Override
    public TabInfoEntity createOriginEntityNewInstance() {
        return new TabInfoEntity();
    }

    @Override
    public TabInfoHistoryEntity createHistoryEntityNewInstance() {
    TabInfoHistoryEntity historyEntity = new TabInfoHistoryEntity();
        return historyEntity;
    }

    @Override
    public boolean isTabHasUsed(Integer tabId) {
        QueryTemplate<ModuleInfoHistoryEntity> queryTemplate = QueryTemplate.getEqQueryTemplate("flag", 1);
        queryTemplate.lambda().nested(c1 -> c1.eq(ModuleInfoHistoryEntity::getTopTabId, tabId).or().eq(ModuleInfoHistoryEntity::getBottomTabId, tabId));
        return moduleInfoHistoryMapper.selectCount(queryTemplate) > 0 || dmpRegistryRlsInfoBiz.isResourceHasUsed(tabId, ResourceTypeEnum.TAB.getValue());
    }
}
